<?php namespace Admin\Controller;
class BrandController extends CommonController{
	private $model;
	public function __auto(){
		$this->model=new \Common\Model\Brand;
	}
	public function index(){
		$data=$this->model->orderBy('sort','DESC')->get();
		if(!$data){
			View::success("请先去添加品牌",U('Brand/add'));
		}
		View::with('data',$data);
		View::make();
	}
	public function add(){
		if(IS_POST){
			p(Q('post.'));
			// exit;
			if($this->model->store()){
				View::success("添加成功",U('Brand/index'));
			}
			View::error($this->model->getError());
		}
		View::make();
	}
	public function edit(){
		if(IS_POST){
			if($this->model->edit()){
				View::success("修改成功",U('Brand/index'));
			}
			View::error($this->model->getError());
		}
		$bid=Q('get.bid',0,'intval');
		$oldData=$this->model->where("bid={$bid}")->find();
		View::with('oldData',$oldData);
		View::make();
	}
	public function del(){
		$bid=Q('get.bid',0,'intval');
		$this->model->where("bid={$bid}")->delete();
		View::success('删除成功',U('Brand/index'));
	}
}